
#import "SceneMenu.h"
#import "SceneBatteryView.h"
#import "SceneOptions.h"
#import "SceneRanking.h"


@implementation Menu

+(id) scene
{
	// 'scene' is an autorelease object.
	CCScene *scene = [CCScene node];
	
	// 'layer' is an autorelease object.
	Menu *layer = [Menu node];
	
	// add layer as a child to scene
	[scene addChild: layer];
	
	// return the scene
	return scene;
}

// on "init" you need to initialize your instance
-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if ( (self=[super init] )) 
	{
		m_windowSize = [[CCDirector sharedDirector] winSize];
		
		if ( m_windowSize.width == 768 )
			m_DeviceKind = DEVICE_IPAD;
		else
			m_DeviceKind = DEVICE_IPHONE;
		
		//bg image
		if ( m_DeviceKind == DEVICE_IPHONE )
			spBackground = [CCSprite spriteWithFile:@"background1.png"];
		else
			spBackground = [CCSprite spriteWithFile:@"background1_pad.png"];
		[spBackground setPosition:ccp(CX,CY)];
		[self addChild:spBackground];
		
		//bg sub images
		currentBatter = [[batter alloc] init];
		if ( m_DeviceKind == DEVICE_IPHONE )
			currentBatter.spBatterReady.position = ccp(BAT_START_X-10, BAT_START_Y-40);
		else
			currentBatter.spBatterReady.position = ccp(BAT_START_X-10, BAT_START_Y+200);
		[self addChild:currentBatter.spBatterReady];
		[self addChild:currentBatter.spBatterSwing];
		[currentBatter.spBatterSwing setVisible: FALSE];
		[currentBatter.spBatterReady runAction:[CCRepeatForever actionWithAction: currentBatter.aniBatterReady]];
		
		spBall1 = [CCSprite spriteWithFile: @"ball.png"];
		[spBall1 setScale:0.7f];
		[spBall1 setPosition: ccp(CX-45,CY+32)];
		[self addChild:spBall1];
		spBall2 = [CCSprite spriteWithFile: @"ball.png"];
		[spBall2 setScale:0.7f];
		[spBall2 setPosition: ccp(CX-63,CY-5)];
		[self addChild:spBall2];
		spBall3 = [CCSprite spriteWithFile: @"ball.png"];
		[spBall3 setScale:0.7f];
		[spBall3 setPosition: ccp(CX-55,CY-42)];
		[self addChild:spBall3];
		
		id rotate1 = [CCRotateBy actionWithDuration:1 angle:360];
		id repeat1 = [CCRepeatForever actionWithAction:rotate1];
		[spBall1 runAction:repeat1];
		id rotate2 = [CCRotateBy actionWithDuration:1 angle:360];
		id repeat2 = [CCRepeatForever actionWithAction:rotate2];
		[spBall2 runAction:repeat2];
		id rotate3 = [CCRotateBy actionWithDuration:1 angle:360];
		id repeat3 = [CCRepeatForever actionWithAction:rotate3];
		[spBall3 runAction:repeat3];
		
		//title image
		CCSprite* spMenuTitle = [CCSprite spriteWithFile:@"menu_title.png"];
		[spMenuTitle setPosition:ccp(CX,SCREEN_HEIGHT-50)];
		[self addChild:spMenuTitle];
		
		isTouchEnabled = YES;
		
		[CCMenuItemFont setFontSize:30];
        [CCMenuItemFont setFontName:@"MarkerFelt-Thin"];
		
        CCMenuItem *start = [CCMenuItemFont itemFromString:@"play" target:self selector:@selector(startGame:)];
		[((CCMenuItemFont *)start).label setColor:ccc3(0,0,0)];	
		
		CCMenuItem *options = [CCMenuItemFont itemFromString:@"practice" target:self selector:@selector(options:)];
		[((CCMenuItemFont *)options).label setColor:ccc3(0,0,0)];	
		
		CCMenuItem *ranking = [CCMenuItemFont itemFromString:@"scores" target:self selector:@selector(ranking:)];
		[((CCMenuItemFont *)ranking).label setColor:ccc3(0,0,0)];
		
		CCMenu *menu = [CCMenu menuWithItems:start, options, ranking, nil];	
        [menu alignItemsVertically];
        [self addChild:menu z:1];
	}
	return self;
}

-(void)startGame: (id)sender {
    BatteryView* gs = [BatteryView node];
    [[CCDirector sharedDirector] replaceScene: (CCScene*)gs];
	
	gameInfo.blnPracticeMode = FALSE;
}

-(void)options: (id)sender {
    Options* os = [Options node];
    [[CCDirector sharedDirector] replaceScene: (CCScene*)os];
	
	gameInfo.blnPracticeMode = TRUE;
}

-(void)ranking: (id)sender {
    Ranking* rs = [Ranking node];
    [[CCDirector sharedDirector] replaceScene:(CCScene*)rs];
}

// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
	// in case you have something to dealloc, do it in this method
	// in this particular example nothing needs to be released.
	// cocos2d will automatically release all the children (Label)
	[currentBatter.spBatterReady release];
	[currentBatter.aniBatterReady release];
	[currentBatter.spBatterSwing release];
	[currentBatter.aniBatterSwing release];
	[currentBatter release];
	
	// don't forget to call "super dealloc"
	[super dealloc];
}

@end





